﻿using System;
using System.Collections.Generic;
using System.Text;

namespace BlackXS.Secure
{
   static class PasswordHandler
   {
       static public String ReadPassword()
       {
           string passwort = "";
           ConsoleKeyInfo Key;
           do
           {
               Key = Console.ReadKey();

               if (Key.Key == ConsoleKey.Backspace)
               {
                   if (passwort.Length != 0)
                   {
                       Console.Write(' ');
                       Console.SetCursorPosition(Console.CursorLeft - 1, Console.CursorTop);
                       passwort = passwort.Substring(0, passwort.Length - 1);
                   }
               }
               else if (Key.Key != ConsoleKey.Enter)
               {
                   Console.SetCursorPosition(Console.CursorLeft - 1, Console.CursorTop);

                   if (Convert.ToInt32(Key.KeyChar) != 0)
                   {
                       Console.Write('*');
                       passwort += Key.KeyChar;
                   }
               }
           }

           while (Key.Key != ConsoleKey.Enter && passwort.Length < 33);
           Console.Write("\n");
           return passwort;
       }
    }
}
